<?php
namespace app\api\controller\quot;
use think\File;
use think\facade\Env;
use app\common\model\user\User as UserModel;
use app\common\model\company\Company;
use app\common\model\orderdata\Goods;
use app\common\model\quotation\QuotationList;
use app\common\model\power\Rolepower;
use app\api\controller\Base;

class Quotation extends Base
{
	/**
	 * 产生jwt加密串，参考session
	 */
    public function initialize(){
		parent::initialize();
		self::is_login();
		$type = input('Type');
		if($type=='hawa'){
			Rolepower::powerguard(101004);
		}elseif($type=='buss'){
			Rolepower::powerguard(201005);
		}else{
			moerr('参数错误');
		}
	}

	/**
	 * 获取当前有效的报价信息
	 * 同时返回公司电话
	 * @return [type] [description]
	 */
	public function index(){
		$qu = QuotationList::getinfo();
		//为空则给企业返回修改信息
		if($qu['code']){
			$qu['msg']['CELLPHONE'] = CELLPHONE;
			$qu['msg']['Power'] = Rolepower::ispower('101002');
			return myok($qu['msg']);
		}else{
			return myerr($qu['msg']);
		}
	}
	
	/**
	 * 报价查询
	 * 发来产品及重量返回价格
	 * @return [type] [description]
	 */
	public function question(){
		//如果系统选择业务员报价 在产废订单发来询价时直接返回报价类型
		if(input('Type')=='hawa' && HAWAQUOT=='buss'){
			return myok(['hawaquot'=>HAWAQUOT]);
		}

		$goodlist = input('goodlist');
		vali_number_arr($goodlist);
		$qu = QuotationList::getquestion($goodlist);

		if($qu['code']){
			return myok($qu['msg']);
		}else{
			return myerr($qu['msg']);
		}
	}
	/**
	 * 判断账号是否登录
	 * @return boolean [description]
	 */
	private function is_login(){
		$data = UserModel::is_sessionlogin();
		if (!$data['code']) {
			$data['options'] = 'relogin';
			json($data)->send();
			exit;
		}
	}
}
